package cn.nfwx.tv.util;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.kaopiz.kprogresshud.KProgressHUD;

import cn.nfwx.tv.R;

/**
 * Created by zb.liu on 2017/11/21.
 */

public class DialogUtil {
    private  static KProgressHUD loadingProgress;

    public static void showLoadingProgress(Context context){
        loadingProgress= KProgressHUD.create(context)
                .setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
//                        .setLabel("加载中")
//                        .setDetailsLabel("Downloading data")
                .setCancellable(true)
                .setAnimationSpeed(2)
                .setDimAmount(0.5f);
        loadingProgress.show();
    }

    public static void cancleLoadingProgress(){
        if(loadingProgress!=null){
            loadingProgress.dismiss();
        }
    }

    public static  Dialog getDialog(Activity activity,View view,boolean cancelable){
        Dialog dialog=new Dialog(activity, R.style.MyDialog);
        dialog.setContentView(view);
        dialog.setCancelable(cancelable);
        Window dialogWindow = dialog.getWindow();
        WindowManager m = activity.getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高度
        WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        p.height = (int) (d.getHeight() * 0.6); // 高度设置为屏幕的0.6，根据实际情况调整
        p.width = (int) (d.getWidth() * 0.6); // 宽度设置为屏幕的0.65，根据实际情况调整
        dialogWindow.setAttributes(p);
        return dialog;
    }

    public static  Dialog getDialog(Activity activity,View view,boolean cancelable,double scaleHeight,double scaleWidth){
        Dialog dialog=new Dialog(activity, R.style.MyDialog);
        dialog.setContentView(view);
        dialog.setCancelable(cancelable);
        Window dialogWindow = dialog.getWindow();
        WindowManager m = activity.getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高度
        WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        p.height = (int) (d.getHeight() * scaleHeight); // 高度设置为屏幕的0.6，根据实际情况调整
        p.width = (int) (d.getWidth() * scaleWidth); // 宽度设置为屏幕的0.65，根据实际情况调整
        dialogWindow.setAttributes(p);
        return dialog;
    }


}
